﻿using System.Drawing;
using System.Windows.Forms;
using stdole;

namespace Neovolve.Extensibility.VisualStudio.TestProfilerLink
{
    /// <summary>
    /// The <see cref="ConvertImage"/>
    /// class is used to convert <see cref="Image"/> objects
    /// to <see cref="IPictureDisp"/> objects.
    /// </summary>
    internal sealed class ConvertImage : AxHost
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="ConvertImage"/> class.
        /// </summary>
        private ConvertImage()
            : base(null)
        {
        }

        /// <summary>
        /// Converts the specified image.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <returns></returns>
        public static StdPicture Convert(Image image)
        {
            return GetIPictureDispFromPicture(image) as StdPicture;
        }

        /// <summary>
        /// Converts the specified image.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <returns></returns>
        public static StdPicture Convert(Icon image)
        {
            // Convert the icon to an image
            using (Image newImage = image.ToBitmap())
            {
                return Convert(newImage);
            }
        }
    }
}